namespace Maple.Branch.IdentityServer.Services
{
    using System.Threading.Tasks;
    using Entities;
    using IdentityServer4.Stores;
    using IRepositories;
    using Volo.Abp.ObjectMapping;

    public class ClientStore : IClientStore
    {
        protected IClientRepository ClientRepository { get; }

        protected IObjectMapper<IdentityServerDomainModule> ObjectMapper { get; }

        public ClientStore(IClientRepository clientRepository, IObjectMapper<IdentityServerDomainModule> objectMapper)
        {
            ClientRepository = clientRepository;
            ObjectMapper = objectMapper;
        }

        public virtual async Task<IdentityServer4.Models.Client> FindClientByIdAsync(string clientId)
        {
            var client = await ClientRepository.FindByCliendIdAsync(clientId);

            return ObjectMapper.Map<Client, IdentityServer4.Models.Client>(client);
        }
    }
}
